/*
 * @Author: 小花
 * @Date: 2022-04-14 08:31:11
 * @LastEditors: 小花
 * @LastEditTime: 2022-05-19 23:26:35
 * @FilePath: /adminClient/src/plugins/request/http.ts
 * @Description:
 */
import { IAdmin } from '@/model/main/layout/dynamicNav/AdminPage'
import { IAnnouncement } from '@/model/main/layout/dynamicNav/AnnouncementPage'
import { IBeginEndTime } from '@/model/main/layout/dynamicNav/OrdersManagePage'
import { IUserRole } from '@/model/main/layout/dynamicNav/PermissionPage/UserRole'
import { IUser } from '@/model/main/layout/dynamicNav/UserPage'
import { IWorker } from '@/model/main/layout/dynamicNav/WorkerPage'
import axios from './axios'

// --------------------------------登录请求区--------------------------------

/**
 * @description: 获取密钥信息
 * @param {*}
 * @return {*}
 */
export const PullKey = () => {
  return axios.post('/login/getKey')
}

/**
 * @description: 登录请求
 * @param {string} data
 * @return {*}
 */
export const LoginStart = (data: string) => {
  return axios.post('/login/start', data)
}

/**
 * @description: 验证登录有效性
 * @param {*}
 * @return {*}
 */
export const verifyLoginOverdue = () => {
  return axios.get('/login/overdueVerify')
}

/**
 * @description: 退出登录
 * @param {*}
 * @return {*}
 */
export const signOut = () => {
  return axios.get('/login/out')
}

// --------------------------------首页请求区--------------------------------

/**
 * @description: 本月报修量、上月报修量、本年报修量、上年报修量
 * @param {*}
 * @return {*}
 */
export const repairAmountQuery = () => {
  return axios.get('/home/repairAmountQuery')
}

/**
 * @description: 年度报修类别统计
 * @param {number} year 年
 * @return {*}
 */
export const annualRepairStatist = (year: number) => {
  return axios.get('/home/annualRepairStatist', { params: { year } })
}

/**
 * @description: 年度报修量趋势
 * @param {number} year
 * @return {*}
 */
export const annualRepairTrend = (year: number) => {
  return axios.get('/home/annualRepairTrend', { params: { year } })
}

/**
 * 修改密码
 * @param data 公钥加密的新旧密码
 * @returns
 */
export const updatePass = (data: string) => {
  return axios.post('/home/updatePass', data)
}

// --------------------------------维修员请求区--------------------------------

/**
 * @description: 获取所有维修员信息
 * @param {*}
 * @return {*}
 */
export const pullAllWorker = () => {
  return axios.get('/worker/pullAllWorker')
}

/**
 * @description: 更新维修员信息
 * @param {IWorker} data 更新数据
 * @return {*}
 */
export const updateWorker = (data: IWorker) => {
  return axios.post('/worker/updateWorker', data)
}

/**
 * @description: 删除维修员
 * @param {IWorker} data 更新数据
 * @return {*}
 */
export const delWorker = (data: IWorker) => {
  return axios.post('/worker/delWorker', data)
}

/**
 * @description: 新增维修员
 * @param {IWorker} data 新增数据
 * @return {*}
 */
export const addNewWorker = (data: IWorker) => {
  return axios.post('/worker/addNewWorker', data)
}

/**
 * @description: 批量添加维修员
 * @param {IWorker} data 新增数据
 * @return {*}
 */
export const addNewWorkers = (data: IWorker[]) => {
  return axios.post('/worker/addNewWorkers', data)
}

/**
 * @description: 查看新增维修员注册状态
 * @param {*}
 * @return {*}
 */
export const pullNewWorkerRegState = () => {
  return axios.get('/worker/pullNewWorkerRegState')
}

// --------------------------------管理员请求区--------------------------------

/**
 * @description: 拉取所有管理员信息
 * @param {*}
 * @return {*}
 */
export const pullAllAdmin = () => {
  return axios.get('/admin/pullAllAdmin')
}

/**
 * @description: 新增管理员
 * @param {IAdmin} data 新增数据
 * @return {*}
 */
export const addNewAdmin = (data: IAdmin) => {
  return axios.post('/admin/addNewAdmin', data)
}

/**
 * @description: 管理员工作转岗
 * @param {IAdmin} data 更新数据
 * @return {*}
 */
export const muddleheaded = (data: IAdmin) => {
  return axios.post('/admin/muddleheaded', data)
}

/**
 * @description: 删除管理员
 * @param {IAdmin} data 实例对象
 * @return {*}
 */
export const delAdmin = (data: IAdmin) => {
  return axios.post('/admin/delAdmin', data)
}

// --------------------------------普通用户请求区--------------------------------

/**
 * @description: 拉取普通用户信息
 * @param {*} current 当前页
 * @param {*} size 当前页数据量
 * @return {*}
 */
export const pullUserPage = (current = 1, size = 100) => {
  return axios.get('/user/pullUserPage', { params: { current, size } })
}

/**
 * @description: 删除普通用户
 * @param {IUser} data 实例对象
 * @return {*}
 */
export const delUser = (data: IUser) => {
  return axios.post('/user/delUser', data)
}

// --------------------------------公告请求区--------------------------------

/**
 * @description: 拉取所有公告信息
 * @param {*}
 * @return {*}
 */
export const pullAllAnnouncement = () => {
  return axios.get('/announcement/pullAllAnnouncement')
}

/**
 * @description: 发布公告
 * @param {IAnnouncement} data 实例对象
 * @return {*}
 */
export const issueAnnouncement = (data: IAnnouncement) => {
  return axios.post('/announcement/issueAnnouncement', data)
}

/**
 * @description: 删除公告
 * @param {IAnnouncement} data 实例对象
 * @return {*}
 */
export const delAnnouncement = (data: IAnnouncement) => {
  return axios.post('/announcement/delAnnouncement', data)
}

// --------------------------------财务管理请求区--------------------------------

/**
 * @description: 查询年度收支情况
 * @param {number} year
 * @return {*}
 */
export const queryYearFinancial = (year: number) => {
  return axios.get('/financial/yearSpendingAndIncomeFinancial', { params: { year } })
}

/**
 * @description: 查询年度增长量及增长率
 * @param {*}
 * @return {*}
 */
export const queryYearSpendingRate = () => {
  return axios.get('/financial/yearSpendingRate')
}

// --------------------------------订单管理请求区--------------------------------

/**
 * @description: 拉取报修订单信息列表
 * @param {IBeginEndTime} data 批量时间范围内的订单信息
 * @return {*}
 */
export const pullOrderList = (date?: IBeginEndTime) => {
  return axios.post('/orders/pullOrderList', date)
}

/**
 * @description: 删除订单
 * @param {string} data 订单id
 * @return {*}
 */
export const delOrders = (data: string[]) => {
  return axios.post('/orders/delOrders', data)
}

// --------------------------------权限管理请求区--------------------------------

/**
 * @description: 拉取角色信息
 * @param {*}
 * @return {*}
 */
export const pullRole = () => {
  return axios.get('/permission/pullRole')
}

/**
 * @description: 添加角色
 * @param {string} role 角色
 * @return {*}
 */
export const addRole = (role: string) => {
  return axios.get('/permission/addRole', { params: { role } })
}

/**
 * @description: 删除角色
 * @param {string} roleId 角色ID
 * @return {*}
 */
export const delRole = (roleId: string) => {
  return axios.get('/permission/delRole', { params: { roleId } })
}

/**
 * @description: 拉取权限信息
 * @param {*}
 * @return {*}
 */
export const pullPermission = () => {
  return axios.get('/permission/pullPermission')
}

/**
 * @description: 添加权限
 * @param {string} permission 权限名
 * @return {*}
 */
export const addPermission = (permission: string) => {
  return axios.get('/permission/addPermission', { params: { permission } })
}

/**
 * @description: 删除权限
 * @param {string} permId 权限
 * @return {*}
 */
export const delPermission = (permId: string) => {
  return axios.get('/permission/delPermission', { params: { permId } })
}

/**
 * @description: 拉取角色权限关联信息
 * @param {*}
 * @return {*}
 */
export const pullRolePermission = () => {
  return axios.get('/permission/pullRolePermission')
}

/**
 * @description: 添加角色权限
 * @param {Map} rolePermission 角色权限
 * @param {*} any
 * @return {*}
 */
export const addRolePermission = (rolePermission: any) => {
  return axios.post('/permission/addRolePermission', rolePermission)
}

/**
 * @description: 拉取用户角色信息
 * @param {number} currnet 当前页
 * @param {number} size 当前页大小
 * @return {*}
 */
export const pullUserRole = (currnet?: number, size?: number) => {
  return axios.get('/permission/pullUserRole', { params: { currnet, size } })
}

/**
 * @description: 禁用用户角色
 * @param {IUserRole} data 用户角色对象
 * @return {*}
 */
export const toggleRole = (data: IUserRole) => {
  return axios.post('/permission/toggleRole', data)
}

/**
 * @description: 根据 userId 用户ID 查询用户角色关联信息
 * @param {string} userId 用户ID
 * @return {*}
 */
export const queryByUserId = (userId: string) => {
  return axios.get('/permission/queryByUserId', { params: { userId } })
}

/**
 * @description: 根据 roleIds 角色ID 查询用户角色关联信息
 * @param {string} roleIds
 * @return {*}
 */
export const queryByURoleId = (roleIds: string) => {
  return axios.post('/permission/queryByURoleId', roleIds)
}

/**
 * @description: 根据 enabled 状态 查询用户角色关联信息
 * @param {boolean} enabled
 * @return {*}
 */
export const queryByEnabled = (enabled: boolean) => {
  return axios.get('/permission/queryByEnabled', { params: { enabled } })
}

/**
 * @description: 编辑用户权限
 * @return {*}
 */
export const editUserPermission = (data: {
  userId: string;
  editPermission: string[];
}) => {
  return axios.post('/permission/editUserPermission', data)
}
